{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-20T12:56:32.589377Z",
     "start_time": "2025-03-20T12:56:30.308088Z"
    }
   },
   "source": "from sklearn.feature_extraction.text import CountVectorizer",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T12:56:34.229014Z",
     "start_time": "2025-03-20T12:56:34.223292Z"
    }
   },
   "cell_type": "code",
   "source": [
    "corpus = [\n",
    "    \"This is the first document.\",\n",
    "    \"This is the second document.\",\n",
    "    \"And this is the third one.\",\n",
    "    \"Is this the first document?\",\n",
    "]"
   ],
   "id": "3f904f9dc421f694",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T12:56:36.708016Z",
     "start_time": "2025-03-20T12:56:36.700670Z"
    }
   },
   "cell_type": "code",
   "source": "vectorizer = CountVectorizer()",
   "id": "c0ad5a90ca4eb0ab",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T12:56:47.854326Z",
     "start_time": "2025-03-20T12:56:47.845808Z"
    }
   },
   "cell_type": "code",
   "source": "X = vectorizer.fit_transform(corpus)",
   "id": "4c587cc1ebdeb6fe",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T12:59:04.451073Z",
     "start_time": "2025-03-20T12:59:04.443344Z"
    }
   },
   "cell_type": "code",
   "source": "print(vectorizer.get_feature_names_out())",
   "id": "61c2a143ff0ee50e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['and' 'document' 'first' 'is' 'one' 'second' 'the' 'third' 'this']\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T12:59:34.329015Z",
     "start_time": "2025-03-20T12:59:34.317897Z"
    }
   },
   "cell_type": "code",
   "source": "print(X.toarray())",
   "id": "e4442bd570124e70",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 1 1 0 0 1 0 1]\n",
      " [0 1 0 1 0 1 1 0 1]\n",
      " [1 0 0 1 1 0 1 1 1]\n",
      " [0 1 1 1 0 0 1 0 1]]\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "69ef646589d1989f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
